SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Essex
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dynamically changing text box value from a select box

    Hi,

    I have a drop down box on a site, and when an option is selected, I need the value of a text box to change.

    My form has the following in it:
    Code:
    <select name="event">
    <option value="" onclick="updateprice(0)">Please Select..</option>
    <option value="3" onclick="updateprice(25)">Monday 16th February 2004 (25 per ticket)</option>
    <option value="2" onclick="updateprice(20)">Saturday 28th February 2004 (20 per ticket)</option>
    </select>
    and I have this javascript function:
    Code:
    function updateprice(theamount) {
    	document.nonmember.adminprice.value = theamount
    }
    the form is called 'nonmember' and the text box i need to change is called 'adminprice'.

    Everything works fine in mozilla, but in IE nothing happens when I select an item from the drop down list (not even a javascript error)

    Any help is apreciated

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that the problem is that you're checking for an action on the individual options rather than the select.

    This works in IE6: DEMO, but I'm equally sure that I've been shown a more concise way of doing the same thing in this forum and yet can't turn up the code.

    Anyway, here goes:
    Code:
    <html>
      <head>
    	<script language="JavaScript" type="text/javascript">
    	<!--
    	  function updateprice(selectId){
    		var Sel_Ind = document.getElementById(selectId).selectedIndex;
    		var theamount = document.getElementById(selectId).options[Sel_Ind].value;
    		document.getElementById('adminprice').value = theamount;
    	  }
    	//-->
    	</script>
      </head>
      <body>
    	<form name="nonmember">
    	  <select id="event" onChange="updateprice(this.id);">
    		<option value="0">Please Select..</option>
    		<option value="25">Monday 16th February 2004 (25 per ticket)</option>
    		<option value="20">Saturday 28th February 2004 (20 per ticket)</option>
    	  </select>
    	  <input type="text" id="adminprice" value="0" />
    	</form>
      </body>
    </html>
    Andy
    From the English nation to a US location.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <title>untitled</title>
    </head>
    <body>
    <form name"nonmember">
    Event Date___<select name="event" onchange="adminprice.value=options[selectedIndex].value">
    <option value="0" selected="selected">Please Select..</option>
    <option value="25">Monday 16th February 2004 (25 per ticket)</option>
    <option value="20">Saturday 28th February 2004 (20 per ticket)</option>
    </select>
    Event Price___<strong>&#163; </strong><input type="text" name="adminprice" value="0" size="2" readonly="readonly">
    </form>
    </body>
    </html>
    ::: certified wild guess :::

  4. #4
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The beauty and simplicity of that almost brought a tear to my eye. Yay!


    Andy
    From the English nation to a US location.

  5. #5
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Essex
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help, although the problem with your solutions is that i need to use the value of the select item for the price.
    That value is needed because its the ID of the event, and this needs to be submitted with the form so the next page knows what event is being edited.

    I got around the problem by putting the prices into a javascript array first, although it doesnt work in mozilla, the only person who will use this page swears by IE

  6. #6
    SitePoint Member
    Join Date
    Mar 2005
    Location
    London
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just want to say thanks to adios for the simple and very elegant solution - I just implemented it and it has saved me much headaches.

    thanks again,

    Matt S

  7. #7
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    flash forms

    any idea how to do this with flash forms in mx7?


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
  •