Guber-X Posted April 3, 2012 Share Posted April 3, 2012 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 ] Quote Link to comment https://forums.phpfreaks.com/topic/260290-selected-option-send-value-to-textarea-help/ Share on other sites More sharing options...
Guber-X Posted April 3, 2012 Author Share Posted April 3, 2012 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]')"> Quote Link to comment https://forums.phpfreaks.com/topic/260290-selected-option-send-value-to-textarea-help/#findComment-1334148 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.