Jump to content

[SOLVED] Append value to text field


SkyRanger

Recommended Posts

I am not looking for somebody to write me a script, if I was then I am posting in the wrong section.  What I am looking for though is if anybody knows where I can find a tutorial for either a php or javascript /mysql Address Book script.  I figure javascript because I don't think PHP can do this, but if it can, can somebody point me in the right direction.

 

Here is what I am looking for.  User clicks on addressbook link.  chooses name, auto inserts into To: field.  I can already populate the address book from mysql but need to figure out how to get it moved over without having to close the addressbook.

 

Anybody have any ideas?

Link to comment
Share on other sites

Ok, scrapped the popup box move to text box script.  Decided to try and figure an easier way to to this.

 

On the same page.

 

I have a list of names:

 

John

Jane

Bob

Marc

Chris

 

I want to be able to click on a radio button beside there name and have it automatically insert into a text box?

 

Any ideas?

Link to comment
Share on other sites

Ok, this is what I have so far but it doesn't seem to be working:

 

<script>
function insertext(text,area)
{
if(document.getElementById(name))
{
document.name.focus();
document.name.value = document.name.value + " " + text
document.name.focus();
}
}
</script>
</head>
<body>

<form method="post" action="send.php">
bunch of other form entries here...

To: <input type="text" name="to_name" size="30">

</form>

List of Entries to choose from:

<?

$resultab = mysql_query( "SELECT * from address where fname='$loggeduser'") or die( "Unable to select database");
                $wordnum = mysql_num_rows( $resultab );

	while( $rowab = mysql_fetch_array( $resultab ) )
{
$toname = $rowab['abname'];
echo "<a href=\"#\" onclick=\"javascript: insertext('$toname','to_name');\">".$rowab['abname']."";
echo "<br>";
}

?>

 

I am using FF and IE and it won't work in either.

Link to comment
Share on other sites

Decided to go a different root because I couldn't figure the code out.  I code php and not javascript but unfortionatly I need it for my script to work.

 

Here is what I came up with so far but still having problems:

 

echo "<input name=\"sendto\" type=\"radio\" id=\"to_name1\" value=\"".$rowab['abname']."\">".$rowab['abname']."";
echo "<br>";
}
?><button onclick="document.getElementById('to_name2').value=
document.getElementById('to_name1').value">Add Name</button>


<input type="text" name="to_name" id="to_name2" size="30">

 

The first radio button works in the list,(So when i hit add name it will echo the first radiobutton to the text box) but after that it only echos the first one into the text box.  Can anybody give me a hand trying to figure out why?

Link to comment
Share on other sites

The problem is that it will not choose the second,third, etc, with the code I displayed.  It always defaults to the first radio button and echos that value.  I know nothing about javascript.  I got lucky when I got as far as I did after searching on the net.

Link to comment
Share on other sites

instead of going back and forward, this will get you started.

<script language="javascript">
function fill_name(val){
	document.getElementById('to_name2').value = val;
}
</script>
<a href="#" onclick="fill_name('Joe Dirt'); return false;">Joe Dirt</a><br />
<a href="#" onclick="fill_name('Joe Dirt 1'); return false;">Joe Dirt 1</a><br />
<a href="#" onclick="fill_name('Joe Dirt 2'); return false;">Joe Dirt 2</a><br />
<a href="#" onclick="fill_name('Joe Dirt 3'); return false;">Joe Dirt 3</a><br />
<a href="#" onclick="fill_name('Joe Dirt 4'); return false;">Joe Dirt 4</a><br />
<a href="#" onclick="fill_name('Joe Dirt 5'); return false;">Joe Dirt 5</a><br />
<input type="text" name="to_name" id="to_name2" size="30">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.