Jump to content

Selected Option send value to textarea Help


Guber-X

Recommended Posts

I am writing a simple form for a admin section to a website im building. it is set up basically like a "Topic Post". its got ur buttons for bbcode inserts. I have the buttons work so when you click on them it sends the bbcode to textarea. but I as having troubles to get it to work with the "options" input.

 

here is what i have so far for code:

 

JS:

<script type="text/javascript"> 
<!--

//myField accepts an object reference, myValue accepts the text strint to add 
function insertAtCursor(myField, myValue) { 
//IE support 
if (document.selection) { 
myField.focus();

sel = document.selection.createRange(); 
sel.text = myValue; 
}

//Mozilla/Firefox/Netscape 7+ support 
else if (myField.selectionStart, myField.selectionStart == '0') {

var startPos = myField.selectionStart; 
var endPos = myField.selectionEnd; 
myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length); 
} else { 
myField.value += myValue; 
} 
}

//--> 
</script>

 

HTML:

<button title="Bold" onclick="insertAtCursor(document.getElementById('info'),'[b][/b]')"><b>B</b></button>
   <button title="Italic" onclick="insertAtCursor(document.getElementById('info'),'[i][/i]')"><i>i</i></button>
   <button title="URL Links" onclick="insertAtCursor(document.getElementById('info'),'[url][/url]')">Links</button>
   Font Size: <select name="size" onchange="insertAtCursor(document.getElementById('info'),'[size=][/size]')">
   	<option value="14">14px</option>
    <option value="16">16px</option>
    <option value="18">18px</option>
    <option value="20">20px</option>
    <option value="22">22px</option>
    <option value="24">24px</option>
    <option value="26">26px</option>
   </select>
   <?php
$e_result = mysql_query("SELECT * FROM info ORDER by id DESC LIMIT 1")
   or die("query failed: " . msql_error());
 while($row = mysql_fetch_array($e_result)) {
	 list($id, $info) = $row;
	 ?>
         <textarea form="info" id="info" name="info" cols="88" rows="5" autofocus="autofocus"><?php echo $info; ?></textarea>
         <?php
 }
?>

 

as far as what i have. it all works but I would like to get the value of the size to display the value as well. something like this [ size=valuehere ][ /size ]

Link to comment
Share on other sites

after a but more research I have finally got it to work.

 

simple enough, all i had to do was this in the "select" tag

go from this
<select name="size" id="size" onchange="insertAtCursor(document.getElementById('info'),'[size=][/size]')">

to this

<select name="size" id="size" onchange="insertAtCursor(document.getElementById('info'),'[size=' + document.getElementById('size').value + '][/size]')">

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.