rockinaway Posted October 25, 2007 Share Posted October 25, 2007 I am fairly new to javascript. I have a function that assigns values to a hidden form input via an iframe. This is all being put into PHP... For my form, the process if being called in the onSubmit call: onSubmit="return do(form, content)" I have put the arguments form and content in so the function can be used for several different forms with different names. My function is: function do(aForm, aContent) { pText = box.document.body.innerHTML; document.aForm.aContent.value = pText; } NOTE: the variable box has been defined early and it works in other functions.. Now the problem I am getting is that the arguments I give the function and used as aForm and aContent in the function.. but these values are not replaced with the arguments I give the function, so instead of doing document.form.content.value = pText, it does what is put there, document.aForm.aContent.value = pText... Why does it do this? Why won't it replace the values? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 25, 2007 Share Posted October 25, 2007 What you are tyring to do is access the element through object/array notation. It is a lot easier to access it by its id. So if you have <input type="text" id="test_id" /> you could easily get to it, as long as it exists in the dom, by doing document.getElementById('test_id'); so to change your do() function around do(ele_id){ document.getElementById(ele_id).value = box.document.body.innerHTML; } You'll just have to give your element uinque ids. Try that out Quote Link to comment Share on other sites More sharing options...
rockinaway Posted October 25, 2007 Author Share Posted October 25, 2007 Wow.. fixed it that worked.. but it was also a mistake with my HTML.. missed the closing /.. made all the difference.. thanks! Quote Link to comment Share on other sites More sharing options...
rockinaway Posted October 25, 2007 Author Share Posted October 25, 2007 Another thing.. if I try giving the function an argument and looking for matches it doesn't work :S i.e. I call the function with action(text) Then my function would be something like: function action(area) { if (area == "image") *do something*; else if (area == "text") do something; else *do something else* } But that doesn't work.. why? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted October 25, 2007 Share Posted October 25, 2007 Because you need to pass it a string when you call it: action('text'); 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.