Jump to content

Function arguments..


rockinaway

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/74719-function-arguments/
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/74719-function-arguments/#findComment-377847
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/74719-function-arguments/#findComment-377945
Share on other sites

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.