Jump to content

retrieve value from repeat region using onclick


xjx424
 Share

Recommended Posts

Hi,I am trying to copy a value from one input to another. My problem is that one of the values is in a repeat region. I figured I would try and create a loop but I don't know if I'm even close to doing it right. My goal is to have the "from" input show up in the "to" input. Here's what I have.

<html><head><script type="text/javascript">function moveBody() {	var to = document.getElementById('to').value;	var from = document.getElementById('from').value; 		for(var i = 0; i < from.length; i++) {		to = from[i]; }}</script></head><body><table>  <tr>    <td><input type="text" id="to"></td>  </tr></table><table>  <?php do { ?>    <tr>      <td><input type="text" id="from" value="<?php echo $row_rsEmail['to_email']; ?>">        <input type="button" onClick="moveBody()" value="Click"></td>    </tr>    <?php } while ($row_rsEmail = mysql_fetch_assoc($rsEmail)); ?></table></body></html>

All suggestions are appreciated.

Link to comment
Share on other sites

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

So do you want the value of the first input box to shift to the second one, leaving the first one blank when the user hits the button?PS: the value of your second box is <?php echo $row_rsEmail['to_email']; ?> in words when a first opened the browser page but the refresh doesn't make it come back. I don't know php, but I assume you don't want that to show but rather to do something?

Link to comment
Share on other sites

So I got a little progress, How is this:

<script type="text/javascript">function moveBody() {document.getElementById("from").value = document.getElementById("to").value;}</script>

That takes the value that was in the "From", or lower box and puts it in the "to" or box on top. Both of them now have the same value. Is that what you want?

Link to comment
Share on other sites

Does that mean you will have multiple from boxes or something? Can I see the whole code, I'm not quite sure what you mean by repeating region for every row?

Link to comment
Share on other sites

Here's the page: http://annearundelproperties.net/agents/emails/sent.phpIt's an email page where when you click on a row on the left the message will appear on the right. This part here loops through the database pulling out all email addresses and creating the list you see.<?php do { ?><tr><td><input type="text" id="from" value="<?php echo $row_rsEmail['to_email']; ?>"><input type="button" onClick="moveBody()" value="Click"></td></tr><?php } while ($row_rsEmail = mysql_fetch_assoc($rsEmail)); ?>

Link to comment
Share on other sites

var frombox = document.getElementsById("from").value;for (var i = 0, frombox[i], i++) { frombox[i] = document.getElementById("to").value}

I don't know maybe that is what you're looking for?

Link to comment
Share on other sites

Ok I may have made a mistake in the code let me try again

var frombox = document.getElementsById("from");for (var i = 0, frombox[i], i++) {frombox[i].value = document.getElementById("to").value

Link to comment
Share on other sites

You have this so far

function moveBody() {    var link = document.getElementById('body_link');    for(var i = 0; i < link.length; i++) {            link[i].onclick = document.getElementById('body_text').value = document.getElementById('email_body').value;			    }}

try changing it to this

function moveBody() {	var link = document.getElementsById('body_link'); // add an s to Element here. You want to get all of them	for(var i = 0; i < link.length; i++) {			link[i].onclick = function movebody2() { //make this a function here					  link[i].value = document.getElementById('email_body').value;			}				}}

Link to comment
Share on other sites

You know xjx424, I'm about as stumped as you. Lol. Sorry man I tried.About the 's' at the end, I used it in getElementsByTagName but i'm not sure if it works in Id. I think it makes it plural but again I'm not entirely sure. I'm not an expert, just a trial and error guy.EruEDIT: actually, let me try again I'm going to look at one of my old posts about something. one sec

Link to comment
Share on other sites

OK, I took a look at your code, try making the anchors onclick="moveBody" to onclick="moveBody()" add the parantheses

Link to comment
Share on other sites

TRY this...

function moveBody() {    var link = document.getElementById('body_link'); // add an s to Element here. You want to get all of them    for(var i = 0; i < link.length; i++) {            link[i].onclick = function movebody2() { //make this a function here                      document.getElementById('body_text').value = document.getElementById('email_body').value;            }                }}window.onload= moveBody;

Take all the onclick values off of your anchors. And if all else fails after that turn this line: document.getElementById('body_text').value = document.getElementById('email_body').value; into link.value = document.getElementById('email_body').value;EDIT: also use the 's' after elements in the first one where link is defined.... if all else fails

Link to comment
Share on other sites

You said this one worked?

<script type="text/javascript">function moveBody() {document.getElementById("from").value = document.getElementById("to").value;}</script>

and this is the current one -ish

function moveBody() {   var link = document.getElementsById("body_link");   for(var i = 0; i < link.length; i++) {	link[i].onclick = function movebody2() { 	   link[i].value = document.getElementById("email_body").value;}}}window.onload= moveBody;

I just want to post this to look at the difference if the first one worked I want to see how I can repeat that.

Link to comment
Share on other sites

yep, and here's my most current attempt

function moveBody() {	var link = document.getElementById('body_link'); 	for(var i = 0; i < link.length; i++) {			link[i].onclick = function movebody2() {			var emailBody = document.getElementById('email_body').value;			for(var i = 0; i < emailBody.length; i++) {					  document.getElementById('body_text').value = emailBody[i];					  }			}				}}

Link to comment
Share on other sites

The problem is somewhere in the for loop. I am rebuilding the function from scratch step by step and using alerts to let me know if things are functioning and the no alerts come up when the for loop is in there. We should examine that more closely.

Link to comment
Share on other sites

start with

function init () { alert("Hi this part is working or whatever u want to type here")}window.onload = init;

then build the next part

function init () { var links = document.getElementsByTagName("a"); alert("im working again. Or if you want to you can ask it to spit a variable to see if the variable stored right.")}window.onload = init;

Link to comment
Share on other sites

I am stuck here. I can't think how to get each of the emails values seperately. You cannot use getElementsById with element(s) with an s., so idk. You can use with TagName though.

function init () { var links = document.getElementsByTagName("a"); for (var i = 0; links[i]; i++) {  links[i].onclick = function hiya () {   var bodies = document.getElementById("email_body");   for (var i2 = 0; bodies[i2]; i2++) {   }   alert("yes");  } }}window.onload = init;

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...