davocold Posted April 9, 2012 Share Posted April 9, 2012 i need a function that can change the name of an input text. <input type="text" name="saisie" onkeyup="transcrire()" id="pfc_words" title="<?php echo _pfc("Enter your message here"); ?>"maxlength="<?php echo $max_text_len; ?>"/> Link to comment https://forums.phpfreaks.com/topic/260637-function-to-change-input-text-name/ Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 You want JS/Jquery, what have you tried so far? Link to comment https://forums.phpfreaks.com/topic/260637-function-to-change-input-text-name/#findComment-1335799 Share on other sites More sharing options...
davocold Posted April 9, 2012 Author Share Posted April 9, 2012 You want JS/Jquery, what have you tried so far? Is there a javascript or Jquery code that can change the name "saisie" of the text input to "anothername"? Link to comment https://forums.phpfreaks.com/topic/260637-function-to-change-input-text-name/#findComment-1335806 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 yah, http://api.jquery.com/attr/ Link to comment https://forums.phpfreaks.com/topic/260637-function-to-change-input-text-name/#findComment-1335810 Share on other sites More sharing options...
davocold Posted April 9, 2012 Author Share Posted April 9, 2012 yah, http://api.jquery.com/attr/ thanks, i think am getting somewhere but what am i doing wrong with the following functions <?php function english() { $('#pfc_words').attr('name', 'english'); } function saisie() { $('#pfc_words').attr('name', 'saisie'); } ?> Link to comment https://forums.phpfreaks.com/topic/260637-function-to-change-input-text-name/#findComment-1335815 Share on other sites More sharing options...
nogray Posted April 9, 2012 Share Posted April 9, 2012 You can just use the following document.getElementById('pfc_words').name = 'MY_NEW_NAME'; you don't need jquery or anything else Link to comment https://forums.phpfreaks.com/topic/260637-function-to-change-input-text-name/#findComment-1335871 Share on other sites More sharing options...
davocold Posted April 9, 2012 Author Share Posted April 9, 2012 You can just use the following document.getElementById('pfc_words').name = 'MY_NEW_NAME'; you don't need jquery or anything else thanks, i want the change when a radio button is selected, i mean when i select a radio button i want the name of the pfc_words change to "english". How do i go about doing that? can i use onClick="document.getElementById('pfc_words').name = 'MY_NEW_NAME';" in radio button? Link to comment https://forums.phpfreaks.com/topic/260637-function-to-change-input-text-name/#findComment-1335885 Share on other sites More sharing options...
nogray Posted April 9, 2012 Share Posted April 9, 2012 Yes, your onclick will work. If you want to make a function, you can do the following <input type="radio" onclick="my_name_change_func('english');" .... ... later in your script... function my_name_change_func(nm){ document.getElementById('pfc_words').name = nm; } Link to comment https://forums.phpfreaks.com/topic/260637-function-to-change-input-text-name/#findComment-1335887 Share on other sites More sharing options...
davocold Posted April 9, 2012 Author Share Posted April 9, 2012 Yes, your onclick will work. If you want to make a function, you can do the following <input type="radio" onclick="my_name_change_func('english');" .... ... later in your script... function my_name_change_func(nm){ document.getElementById('pfc_words').name = nm; } thanks alot, i used the onclick and it changes the name but only once, if i click another radio button to change it back to the previous name, it doesn't. would the function way of doing this fix it? Link to comment https://forums.phpfreaks.com/topic/260637-function-to-change-input-text-name/#findComment-1335889 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.