krash11554 Posted August 25, 2012 Share Posted August 25, 2012 I think i sound stupid asking this but i want a input box id to be a javascript variable and text that i write in. var id = 'interior'; <input type="text" id="addcar_ + id + hidden" /> Idk if you guys will understand this Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted August 25, 2012 Share Posted August 25, 2012 you'll need either getElementbyId or jquery's $('#element') Quote Link to comment Share on other sites More sharing options...
krash11554 Posted August 25, 2012 Author Share Posted August 25, 2012 So something like this var id = 'interior'; $('#addcar').attr('id','addcar_' + id + 'hidden'); and the input box is this before i change the id. <input type="text" id="addcar" /> Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 25, 2012 Share Posted August 25, 2012 Why are you trying to do this? Quote Link to comment Share on other sites More sharing options...
codefossa Posted August 27, 2012 Share Posted August 27, 2012 I think you want PHP, not Javascript. You're trying to set it based on a variable during the page load, which Javascript can't do. You could change it after the page loads, but that's completely pointless. You can just set it correctly the first time. <?php // Wherever you set it $id = "interior"; ?> <input type="text" id="<?php echo $id; ?>" /> Remember you can only use an id once, so don't use this for multiple elements. For that you'll want to use a class. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.