Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / January 2006



Tip: Looking for answers? Try searching our database.

auto update on select

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Craig77 - 31 Jan 2006 02:20 GMT
i have a drop down list with values of Organisation Names

when a user selects a Organisation Name i need a text box to be automatically
updated with the Organisations ID

what would be the best way of doing this?

<select name="OrganisationName" id="select4">
                      <cfoutput query="Organ">
                        <option
value="#Organ.OrganName#">#Organ.OrganName#</option>
                      </cfoutput>
</select>

<input type="text" name="OrganisationID"
value="<cfoutput>#Organ.OrganID#</cfoutput>">
Sojovi - 31 Jan 2006 02:44 GMT
Try this (if it's what are you asking for)
Of course is an example, only add the script tag and the "ONCHANGE" to the
dropdown.

Regards

<SCRIPT TYPE="text/javascript">
<!--
function setTextBox(form){
    form.OrganisationID.value=form.OrganisationName.value;
    return true;
}
//-->
</SCRIPT>

<FORM Name="TestForm">
<select name="OrganisationName" id="select4" ONCHANGE="setTextBox(this.form)">
                        <option value="1">Org 1</option>
                        <option value="2">Org 2</option>
                        <option value="3">Org 3</option>
                        <option value="4">Org 4</option>
</select>
<BR>
<input type="text" name="OrganisationID" value="1">
</FORM>
Craig77 - 31 Jan 2006 03:24 GMT
ok thanks for that

the text box is being updated with the OrganisationName, i need this to be Updated with the OrganID
zoeski80 - 31 Jan 2006 04:08 GMT
Craig

The supplied code works fine.

You need to modify your OPTION VALUE="#organ.organName#" to be OPTION VALUE
="#organ.id#" so it will copy the ID value of the organisation into the text
box rather than the name.
Craig77 - 31 Jan 2006 04:30 GMT
Hi Zoe

i cant do that, i need the user to be able select a OrganisationName from the list, then once selected it changes the OrganID in the text box
zoeski80 - 31 Jan 2006 05:46 GMT
Craig

If you want it to function as you have stated you will need to use different
JS to update the text box when the select box is changed, cannot use
OrganisationName.value.

If all you need to do is get the ID/Name combination sent to the next page you
could set the value of the options to be #id#_#name# and then split them up
using ListFirst, ListLast with _ as the delimiter on the process page

OR, If the organisations are coming from the database you can just query the
database again on the process page based on the ID passed through from the form.

OR just have 2 hidden fields for NAME and ID and populate both using JS on the
form - option value="#id#_#name#" then modify the existing JS function to
populate both hidden variables - see attached code.

HTH

<SCRIPT TYPE="text/javascript">
<!--
function setTextBox(){
    var thisValue = document.TestForm.OrganisationSelect.value.split('_') ;
    document.TestForm.OrganisationID.value=thisValue[0];
    document.TestForm.OrganisationName.value=thisValue[1];
    return true;
}
//-->
</SCRIPT>

<FORM Name="TestForm">
<select name="OrganisationSelect" id="select4" ONCHANGE="setTextBox()">
    <option value="1_org1" title="1" id="1">Org 1</option>
    <option value="2_org2" title="2" id="2">Org 2</option>
    <option value="3_org3" title="3" id="3">Org 3</option>
    <option value="4_org4" title="4" id="4">Org 4</option>
</select>
<BR>
<input type="text" name="OrganisationID" value="1">
<input type="text" name="OrganisationName" value="org1">
</FORM>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.