User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 374,148 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,461 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 667 | Replies: 4 | Solved
Reply
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

JavaScript posting data

  #1  
May 13th, 2008
i have created a page which has an iframe held on it i now what to post the data from this iframe and make it available to my other php page. I have researched this a bit and found out it can be done using javascript. the code i have found is this.

<script type="text/javascript">
document.getElementsByName('rand')[0].value = document.getElementsByName('main')[0].src;
</script>

i am not to up on javascript so a little help is needed with this. i know the first element is the name of the hidden input i want to post, were i loose understanding is the next element name. is this the name of the page that the information needs to be posted to or is this how it posts it to the page the iframe is held on (main being the name used for that).
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: JavaScript posting data

  #2  
May 13th, 2008
from my research i think i am beginning to understand this code a bit more but if someone knows if i am wrong please tell me.

as it is asking for the element by name then the number in the [] is not needed as this is the elements id number in the array. So as i have put the name rand in it will already know which element i want to post.

the next part is what i am still struggling to understand. It has the =value section and this is where i am stuck. the value in this section i think must have something to do with where the information is being posted to but as the the page were i found this code did not explain things to greatly i am lost.

please someone explain this code to me or point me in the right direction of were to find a good example and explanation of the code so i can then try to implement the code on to my site.
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: JavaScript posting data

  #3  
May 13th, 2008
i have used a different solution now, still not got that working fully yet.

if someone could send me a link with a good explanation of the above code though that would be great as it is always nice to know how things work when you aint seen them before.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,731
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 323
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: JavaScript posting data

  #4  
May 13th, 2008
<script type="text/javascript">
document.getElementsByName('rand')[0].value = document.getElementsByName('main')[0].src;
</script>
The function getElementsByName returns a nodelist i.e. an array of all the elements which go by that name. Hence the array indexing operator [] is a must. If you are pretty sure that there is only one element on the entire page which goes by that name, you can do document.getElementsByName('name')[0] . The first line probably sets the value of some form element e.g. an input element and the second line probably sets the source of the iframe element which goes by the name of 'main' .
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Feb 2008
Posts: 271
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: JavaScript posting data

  #5  
May 15th, 2008
thank you for the reply
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC