pass php value to html element without using echo -


i getting value php $_get[], , want pass value of simple html input element. know can this:

<?      $value     = $_get['value'];      echo '<input type="text" name="value" value="'.$value.'" />'; ?> 

but there way separate php html, giving value textbox without echoing it?

i create textbox regular html element, , use php in part set value.

the answer of iaroel more practical purposes, liked way accepted answer covered many concerns - think more valuable other users.

you don't want error when $_get['value'] becomes undefined.

<?php $value = isset($_get['value'] ? $_get['value'] : ''); ?> <input type="text" name="value" value="<?php echo $value; ?>"> 

but be mindful malicious data can inserted in $_get['value'] you've got apply proper sanitation $value


with regards "getting $_get['value'] without php"

you can without php script creating small javascript function:

<script type="text/javascript">     function $_get(q,s) {          s = s ? s : window.location.search;          var re = new regexp('&'+q+'(?:=([^&]*))?(?=&|$)','i');          return (s=s.replace(/^?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeuricomponent(s[1])) : undefined;      }  </script> 

what hell regular expression? it's matter of matching pattern url.

now, can use $_get() method assign value textbox. in example, used jquery:

<script type="text/javascript">     $(document).ready(function() {         $('input[name="value"]').attr('value', $_get('value'));     }); </script> 

now html code simple this:

<input type="text" name="value"> 

reference: http://www.onlineaspect.com/2009/06/10/reading-get-variables-with-javascript/


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -