Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a onclick switch 1

Status
Not open for further replies.

iao

Programmer
Feb 23, 2001
111
US
I have a form where the user picks an item from a select list. The first item is always "NEW", and the remaining items fall underneath. I set up an array so that when the user selects an item, the page is redrawn with the selected item appearing in a text box. So, if the user picks the "NEW" selection, the Name text box now has the value of "NEW". In all instances, the user would rename the value of "NEW" to something else.

When the form is submitted, the action depends on if "NEW" was selected, or if an existing item was selected. What I would like to do is create a switch in the code, so if the user selects "NEW", it will be submitted to ACTIONPAGE_1. If anything else is selected, ACTIONPAGE_2 will be called.

This is the problem. I can't say <CFIF #select_value_query# EQ &quot;NEW&quot;> because since the users are required to change the value from &quot;NEW&quot; to something else, this CFIF statement always returns an error.

What I would like to do is to create a switch to that once the &quot;NEW&quot; value is selected from the select box, I set a switch to a value. That way, on the action page, I can use that value to determine which action page the user goes to.

Any ideas on how to do this? I hope I didn't make this too confusing.


 
I think this might work for you.

<Form name=&quot;Trythis&quot;
method=&quot;post&quot;
Action=&quot;GoHereifitisNewValue.cfm?#URLTOKEN#>
<select name=&quot;Options&quot;
onchange=&quot;top.location.href = this.options[this.selectedIndex].value;&quot;>

<option value=&quot;New&quot; selected>[NEW]</option>
<CFOUTPUT QUERY=&quot;MyQuery&quot;>
<option value=&quot;./GoHereIfItIsSelected.cfm?ID=#Selection_ID#&#URLTOKEN#&quot;>#Selection_Name#</option>
</CFOUTPUT>
</select>
<br>
NEW Option<INPUT name=&quot;NewOption&quot; size=20 type=&quot;text&quot;>
<br>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
</Form>

This will wait for a New value to be entered on submit it will go to the page specified for a NewValue. If the Select box is changed though it will go directly to the page specified for a Selected item carrying the needed value in an URL variable.

Hope it helps. There are a million other ways to do it but this is the first one I thought of. (Actaully I had the code handy) let me know if this does not work for you somehow and we'll come up with something else.

Have fun...
 
Hi tlhawkins,

Thanks for the response. This would probably work, but I don't want to redirect the user to the ActionPage when they click on New.

I was thinking about it this weekend. What I really want is to create a hidden value. Set it to &quot;0&quot;. Then, whenever the user clicks on &quot;New&quot; in the select box, this hidden value will be set to &quot;1&quot;. Then, if they select on any other item, the value will change back from &quot;1&quot; to &quot;0&quot;. Then, when I submit the form, I can direct the user to the proper page based on the value of the hidden variable.

Any ideas on how to do this? As I am a CF newbie, I am not the most intelligent person when it comes to CF. However, my best guess would be to set an ONCLICK attribute to the selection tag. This ONCLICK attribute could change the value of 0 to 1. However, I have no idea on how to do this. Do you have a best guess? Would this have to involve Javascript?
 
That can be done...

What might work as well (And will avoid getting an empty string in the NEW field) is to check the NEW field on your action page and if it has content go with that. Otherwise use the Select field.

But here is some code that does something very similar to what you asked last, I'm sure you could adapt it:

Code:
<script language=&quot;javascript&quot;>
  function enable(){
       document.Test.Ent.disabled = false;
       document.Test.Sel.disabled = true;
       document.Test.Sel.enabled = false;
       document.Test.Ent.enabled = true;  
       return false;
      
  }
function disable(){
    
       document.Test.Sel.disabled = false;
       document.Test.Sel.enabled = true;
       document.Test.Ent.disabled = true;
       document.Test.Ent.enabled = false;  
       return false;
  }
</script>

<Form name=&quot;Test&quot; action=&quot;look.cfm&quot; method=&quot;Post&quot;>
<input type=&quot;radio&quot; name=&quot;Pick&quot; Onclick=&quot;disable()&quot;>
Select<SELECT NAME=&quot;Sel&quot; >
  <OPTION VALUE = &quot;%&quot;>All</OPTION>
  <OPTION VALUE = &quot;first&quot;>First choice</OPTION>
  <OPTION VALUE = &quot;second&quot;>Second choice</OPTION>
</SELECT><br>
<input type=&quot;radio&quot; name=&quot;Pick&quot; Onclick=&quot;enable()&quot;>
Enter<input type=&quot;text&quot; name=&quot;Ent&quot; size=&quot;30&quot; ><br>

Have fun...
 
Ok, I'll give it a try. Thanks for the help!
 
OK,

Just post if you have any problems with it.

Glad to help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top