Connecting Tech Pros Worldwide Help | Site Map

Change Form input text name=""

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 11th, 2006, 01:25 PM
dhughey@gmail.com
Guest
 
Posts: n/a
Default Change Form input text name=""

I am using

<script type="text/javascript">
function setAction(frm){
act = '';
for(x=0;x<frm.se.length;x++){
if(frm.se[x].checked){
act = frm.se[x].value;
}
}
if(act == 'MINE'){
frm.action = 'MYSEARCHENGINE.HTML';
}
else if(act == 'OTHER'){
frm.action = 'OTHERSEARCHENGINE.HTML';
}
else{
alert('Please choose an option');
return false;
}
}
</script>

to change the intended search engine with radio buttons.
That works well, however...
I also need to change the name="" of an <input type=text base on which
radio button is chosen.
The two searches require different names for that field.

Can someone please help me with this, or have a working example of one
text input field being submited to a choice of search engines.

Thank you very much in advance.
Devin


  #2  
Old May 11th, 2006, 01:55 PM
ASM
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

dhughey@gmail.com a écrit :[color=blue]
>
> That works well, however...
> I also need to change the name="" of an <input type=text base on which
> radio button is chosen.
> The two searches require different names for that field.[/color]

<script type="text/javascript">
function setAction(frm){
act = '';
for(x=0;x<frm.se.length;x++){
if(frm.se[x].checked){
act = frm.se[x].value;
}
}
if(act == 'MINE'){
frm.action = 'MYSEARCHENGINE.HTML';
frm[0].name = 'search';
}
else if(act == 'OTHER'){
frm.action = 'OTHERSEARCHENGINE.HTML';
frm[0].name = 'find';
}
else{
alert('Please choose an option');
return false;
}
return true;
}
</script>

<form action="" onsubmit="return setAction(this)">
<input type=text value="Your search" onclick="this.value=''"> with
MYSEARCHENGINE: <input type=radio name="se" value="MINE"> or
OTHERSEARCHENGINE: <input type=radio name="se" value="OTHER">
<input type=submit value="GO">
</form>


--
Stephane Moriaux et son [moins] vieux Mac
  #3  
Old May 11th, 2006, 03:25 PM
dhughey@gmail.com
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

Thank you for your quick response, but I'm afraid I may not have been
clear.

It is the <input type=text name="THISNAME" that I need to change based
on the radio selection.

  #4  
Old May 11th, 2006, 03:35 PM
dhughey@gmail.com
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

To Be More Clear, here is all of the code I am using. See
CHANGE_WITH_RADIO_SELECTION to see what I need to change with radio
selection.

Thanks again
Devin

<script type="text/javascript">
function setAction(frm){
act = '';
for(x=0;x<frm.se.length;x++){
if(frm.se[x].checked){
act = frm.se[x].value;
}
}
if(act == 'MINE'){
frm.action = 'MYSEARCH';

}
else if(act == 'OTHER'){
frm.action = 'OTHERSEARCH';

}
else{
alert('Please choose an option');
return false;
}
}
</script>
<form action="" onsubmit="return setAction(this)">
<input type=text value="Your Search"
name="CHANGE_WITH_RADIO_SELECTION">
My Search
<input type=radio name="se" value="MINE">
Other Search
<input type=radio name="se" value="OTHER">
<input type=submit value="GO">
</form>

  #5  
Old May 11th, 2006, 03:35 PM
ASM
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

dhughey@gmail.com a écrit :[color=blue]
> Thank you for your quick response, but I'm afraid I may not have been
> clear.
>
> It is the <input type=text name="THISNAME" that I need to change based
> on the radio selection.[/color]

its name have no importance.
function catches this element by its index in the form frm collection

in previous example
<input type=text name="THISNAME"
has to be the first element after opening tag 'form'

<form action="" onsubmit="return setAction(this)">
<input type=text name="THISNAME" value="Your search"
onclick="this.value=''"> with
MYSEARCHENGINE: <input type=radio name="se" value="MINE"> or
OTHERSEARCHENGINE: <input type=radio name="se" value="OTHER">
<input type=submit value="GO">
</form>



--
Stephane Moriaux et son [moins] vieux Mac
  #6  
Old May 11th, 2006, 03:45 PM
ASM
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

dhughey@gmail.com a écrit :[color=blue]
> To Be More Clear, here is all of the code I am using. See
> CHANGE_WITH_RADIO_SELECTION to see what I need to change with radio
> selection.[/color]

what are new names ?
here, in this example,
they'll be 'search' for mine and 'find' for other

<script type="text/javascript">
function setAction(frm){
act = '';
for(x=0;x<frm.se.length;x++){
if(frm.se[x].checked){
act = frm.se[x].value;
}
}
if(act == 'MINE'){
frm.action = 'MYSEARCHENGINE.HTML';
frm[0].name = 'search';
}
else if(act == 'OTHER'){
frm.action = 'OTHERSEARCHENGINE.HTML';
frm[0].name = 'find';
}
else{
alert('Please choose an option');
return false;
}
return true;
}
</script>
<form action="" onsubmit="return setAction(this)">
<input type=text value="Your Search"
name="CHANGE_WITH_RADIO_SELECTION">
My Search
<input type=radio name="se" value="MINE">
Other Search
<input type=radio name="se" value="OTHER">
<input type=submit value="GO">
</form>


Tested in Fx


--
Stephane Moriaux et son [moins] vieux Mac
  #7  
Old May 11th, 2006, 03:45 PM
Randy Webb
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

dhughey@gmail.com said the following on 5/11/2006 11:27 AM:[color=blue]
> To Be More Clear, here is all of the code I am using. See
> CHANGE_WITH_RADIO_SELECTION to see what I need to change with radio
> selection.[/color]

document.forms['formID'].elements['oldNameHere'].name = "newNameHere";

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
  #8  
Old May 11th, 2006, 03:55 PM
dhughey@gmail.com
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

I'm very sorry. I do not want to change the Form Name, I want to change
the

<input type=text name="THIS"

The two searches that I am using require this text field to have
different names.

  #9  
Old May 11th, 2006, 03:55 PM
dhughey@gmail.com
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

I Got it now, thank you. I missed the part where you said the text name
should be first after tag.

Thank you very much

  #10  
Old May 11th, 2006, 04:05 PM
Randy Webb
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

dhughey@gmail.com said the following on 5/11/2006 11:49 AM:[color=blue]
> I'm very sorry. I do not want to change the Form Name, I want to change
> the
>
> <input type=text name="THIS"
>
> The two searches that I am using require this text field to have
> different names.
>[/color]

Answer: They typically post without quoting.

I would give you the question but I would have to quote it first.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Question: How can you spot 90% of Google posters?
  #11  
Old May 11th, 2006, 04:05 PM
ASM
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

Randy Webb a écrit :[color=blue]
> dhughey@gmail.com said the following on 5/11/2006 11:27 AM:
>[color=green]
>> To Be More Clear, here is all of the code I am using. See
>> CHANGE_WITH_RADIO_SELECTION to see what I need to change with radio
>> selection.[/color]
>
>
> document.forms['formID'].elements['oldNameHere'].name = "newNameHere";[/color]

and nextime ?
how to call back oldNameHere ?
(supposing location in a frame or other window)




--
Stephane Moriaux et son [moins] vieux Mac
  #12  
Old May 11th, 2006, 04:05 PM
ASM
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

dhughey@gmail.com a écrit :[color=blue]
> I'm very sorry. I do not want to change the Form Name, I want to change
> the
>
> <input type=text name="THIS"
>
> The two searches that I am using require this text field to have
> different names.[/color]


EXACTELLY what that do !
Did you try it ?

--
Stephane Moriaux et son [moins] vieux Mac
  #13  
Old May 11th, 2006, 04:15 PM
dhughey@gmail.com
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

> I'm very sorry. I do not want to change the Form Name, I want to change[color=blue]
> the[/color]
[color=blue]
> <input type=text name="THIS"[/color]
[color=blue]
> The two searches that I am using require this text field to have
> different names.[/color]

EXACTELLY what that do !
Did you try it ?

Yes, I have it now, I am sorry. I missed your post about having the
text field name first and that did the trick.

You have been very helpful to me and I truley appreciate it.

I am sorry to those of you who are upset about the Non-Quoting. I am
using google temporarily as I do not have a news reader installed on
this maching and it does not quote by default.

Thank you very much.
Devin

  #14  
Old May 11th, 2006, 04:35 PM
Randy Webb
Guest
 
Posts: n/a
Default Re: Change Form input text name=""

ASM said the following on 5/11/2006 12:02 PM:[color=blue]
> Randy Webb a écrit :[color=green]
>> dhughey@gmail.com said the following on 5/11/2006 11:27 AM:
>>[color=darkred]
>>> To Be More Clear, here is all of the code I am using. See
>>> CHANGE_WITH_RADIO_SELECTION to see what I need to change with radio
>>> selection.[/color]
>>
>>
>> document.forms['formID'].elements['oldNameHere'].name = "newNameHere";[/color]
>
> and nextime ?
> how to call back oldNameHere ?
> (supposing location in a frame or other window)[/color]

Then you can check the state of the Radio buttons to determine what the
name of the text input is. Or, you could save a reference to it. Or, you
could use the form index (as you did).

Yours suffers drawbacks as well if the author inadvertently adds a new
input before the desired one.

They both suffer, it is just a matter of which way you want to try to
protect yourself.

The simplest solution to it all is to simply hard code both fields that
are needed for the search engines and then use script to duplicate data.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.