Jump to content

put textfield value to other textfield!


pfkdesign

Recommended Posts

hi guys,

 

i have a problem and perhaps you can help  me ! ??? ???

 

i have a textfiled1 "Menu Name"  and i have another textfield2 "URL" of the menu,by default the value of the url is /controller/ID/ (it is come from database)

what i want is:

when i'm writing in to text field ="label_mnu_1", text field = "url_link_mnu_1" get the value and change the url in to /controller/ID/value texfield1/

<label for="label_mnu_1"> Menu Name</label>
<input type="text" name="label_mnu_1" value="" id="label_mnu_1"/>
                                                                                                                       
<label for="url_link_mnu_1">URL: </label>
<input name="url_link_mnu_1" type="text" id="url_link_mnu_1" value="/controller/ID/$/"  size="30"/>
                                                     put value of label_mnu_1 here ^

 

any idea?

 

thank you in advance

 

Link to comment
https://forums.phpfreaks.com/topic/116598-put-textfield-value-to-other-textfield/
Share on other sites

hi guys,

 

i have a problem and perhaps you can help  me ! ??? ???

 

i have a textfiled1 "Menu Name"  and i have another textfield2 "URL" of the menu,by default the value of the url is /controller/ID/ (it is come from database)

what i want is:

when i'm writing in to text field ="label_mnu_1", text field = "url_link_mnu_1" get the value and change the url in to /controller/ID/value texfield1/

<label for="label_mnu_1"> Menu Name</label>
<input type="text" name="label_mnu_1" value="" id="label_mnu_1"/>
                                                                                                                       
<label for="url_link_mnu_1">URL: </label>
<input name="url_link_mnu_1" type="text" id="url_link_mnu_1" value="/controller/ID/$/"  size="30"/>
                                                     put value of label_mnu_1 here ^

 

any idea?

 

thank you in advance

 

 

This isn't too hard:

<script type="text/javascript">
   window.onload = function()
   {
      var menuName = document.forms["formName"].elements["label_mnu_1"]; //formName is whatever name you've given the form
      var url = document.forms["formName"].elements["url_link_mnu_1"];

      menuName.onblur = function()
      {
         url.value += this.value + '/';
      }
   }
</script>

 

Like I wrote above, "formName" should be replaced by the actual name of the form inside your HTML.  This code modifies the second text input's value when the first input is no longer focused on (i.e., no longer has the cursor).  If you want this to be done based on a submit button being clicked, let me know.  It's almost as easy.

<label for="label_mnu_1"> Menu Name</label>
<input type="text" name="label_mnu_1" value="" id="label_mnu_1" onkeydown="url_link_mnu_1.value='/controller/ID/'+this.value"/>
                                                                                                                       
<label for="url_link_mnu_1">URL: </label>
<input name="url_link_mnu_1" type="text" id="url_link_mnu_1" value="/controller/ID/"  size="30"/>

 

Just put the "/controller/ID/" text into the onkeydown event above the same way that you put it into the value of the input.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.