SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    US
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Newbie

    i'm just getting familiar with javascript. i have a problem, i'm designing a script that takes a number from a disabled text box in a form (which has an initial value of 1) and on pressing a button (on the same form) increments the value in the disabled text box. this is the code i have, but everytime i click on the button, it just address to the #, e.g. it'll be 1111 instead of 4.... i googled this thing but to no avail. here's my script:

    <script language="JavaScript">
    function testresults(form){

    var initvalue = form.calls.value; //get value from textbox calls

    if(initvalue==0){
    form.calls.value = 0;
    } else {
    form.calls.value = initvalue + 1;
    }
    }
    </script>
    <form name="form" method="post" action="">
    Calls
    <input name="calls" type="text" disabled value="1" >
    <input type="button" name="update" value="Submit" onClick="testresults(this.form)">
    </form>

    please nudge me the right direction. TIA

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    US
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry about posting twice, something went wrong with my crappy connection. i apologize.

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's to do with how Javascript handles variables as strings, change
    form.calls.value = initvalue + 1;
    to
    form.calls.value = initvalue - 0 + 1;

    that should do ya


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •