How to assign a button the value of a Javascript f

java , javascript Israel
  • 16 years ago

    Let's say i have a textbox in HTML like this
    <input type=text id=Text1 >
    I tried to add the line this :
    <..... value=GetValue()>
    where GetValue is a JavaScript function i wrote, but Nada, is assigns the value as a string: "GetValue()"


    How to assgin a button or a text box the value returned from a function?

    Would i have to use ASP? cause i don't wanna.

  • 16 years ago

    You can do this straight through JavaScript.  No ASP is needed.
    Try this approach:

    Add the following line in your JavaScript function.  This will set the value of your text field.  (haven't tried this with a button, though, only fields)

    document.myform.fieldname.value = myvalue;

  • 16 years ago

    Another question, if you please.


    How do I tell the script to keep running?

    Meaning I have a JV sub which checks values. How do I make it keep on runnig?
    10x for the previous answer, It helped.

  • 16 years ago

    The script should keep running.  I would have to see the entire script to see where it ends, but the code I mentioned in my previous post will set the value and processing should continue.
    Are you returning False anywhere in your functions?

  • 16 years ago

    I know it resumes running after the assigning but I meant, how do I make an endless loop:

    What I mean is that I want my page to run in an endless loop.
    Or to stop running only at a certain value it occurs, but else it should keep on running CheckVars that checks values:


    function CheckVars(){
       alert("Value is:" + Ocx2.value);
       if (Ocx2.IsAsking ==false)
    }// check vars

    setTimeout ("CheckVars()",1000);


  • 16 years ago

    Try calling this function from a form's OnSubmit button that way it will run the check before it is submitted.  Return a false if there was an invalid entry.

    To create endless loops, you may want to look into Do...While statements or For statements that will run your code until a certain criteria exists.  If this is a web page you probably don't want this.

    I would have to see your code for the entire page to see how you are using it.

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Owning a computer without programming is like having a kitchen and using only the microwave oven” - Charles Petzold