Jump to content


Getting popup data.


9 replies to this topic

#1 _*Creative Insanity_*

  • Guests

Posted 18 April 2007 - 05:53 PM

I am making my own admin editor and there is one small problem I am having.
I have a javascript with functions for the editor which input items into a textarea like thus:
function centerw(input) {
var obj=document.getElementById(input)
obj.value+="#wrapper{ margin:10px auto; width:INSERT IMAGE WIDTH;}"
}
what I am trying to do is from this popup (which is just a hidden div with a form).
function toggleDiv(divid){
	if(document.getElementById(divid).style.display == 'none'){
	  document.getElementById(divid).style.display = 'block';
	}else{
	  document.getElementById(divid).style.display = 'none';
	}
  }
replace the INSERT IMAGE WIDTH with what they entered into the popup. I tried $_GET blah blah but that just inserts the $_GET and I am stumped on how to get the info from the popup and place it where it says INSERT.
Naturally I had the $_GET where is says INSERT but no idea on how to get the popup data and place it in the textarea along with the other info.

Anyone know please?

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 18 April 2007 - 09:53 PM

I'm confused as to what you mean by 'popup'. Is it a prompt box, because the prompt() function will return what the user types. If it is just a hidden div with a form, you the form's method or use JavaScript to grab the value of the form's field and do what it must with it. If it is a completely new window, use the opener object to access the main window's properties and objects.

#3 _*Creative Insanity_*

  • Guests

Posted 19 April 2007 - 01:37 AM

Thanks for the reply Demonslay, it is just a hidden div with a form.
<div id="datain" style="display:none">
	  <form id="data1" name="data1" method="post" action="java script:navcol('thebody'),toggleDiv('datain')">
		<input type="text" name="dataout" id="dataout" />
		<input type="submit" name="Go" id="Go" value="Submit" />
		</form>
	  </div>
But in my editor javascript what ever is entered here
obj.value+="#wrapper{ margin:10px auto; width:INSERT IMAGE WIDTH;}"
get entered.. and that is the part I am stumped on.

#4 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 19 April 2007 - 04:29 PM

Ah, now I can see what you're doing wrong.

You shouldn't use the action property to issue the submit. Use the onsubmit handler, and have it return false so that it doesn't actually submit the form to the server.
Then again, I don't see the point in an actual form if you are using it for DHTML.

I'm getting confused as to how this all works...

You have a textarea element for the main content, I understand. You have a small div that shows up add this CSS rule, and allow them to edit the image width, and add it to the content field. Right?

Why not just use a prompt box, like this.

<!-- Your textarea element here -->
<a href="java script:void(0);" onclick="centerw();">Center Image</a>

<script type="text/javascript">
<!--
centerw(){
var width = prompt('Enter Width of Image in Pixels:', '');
if(width == null) return false;
document.getElementById('textarea').value += '#wrapper{ margin:10px auto; width:'+parseInt(width)+'px;}';
}
-->
</script>

Something like that should work if I'm understanding what you are trying to do.

Edited by Demonslay, 19 April 2007 - 04:30 PM.


#5 _*Creative Insanity_*

  • Guests

Posted 19 April 2007 - 04:46 PM

Thanks once again for the reply demonslay I will try your suggestion.

I know my explanation is not to crash hot, so I will explain this way.

Take a forum editor, if you click on a link button a popup shows and you enter a url and that is placed in your post area with the bbcodes around it.. that is the type of thing I am trying to do.

#6 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 20 April 2007 - 03:40 PM

Ah, yes, thats exactly what the code I gave you does pretty much.

If you're looking for wrapping selections, use this.

/* BBCode Functions */

// Borrowed from [url="http://massless.org/mozedit/"]http://massless.org/mozedit/[/url]
// Written by Chris Wetherell - [url="http://www.massless.org"]http://www.massless.org[/url] - chris [THE AT SIGN] massless.org
function mozWrap(txtarea, openTag, closeTag){
	txtarea = document.getElementById(txtarea);
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) selEnd = selLength;
	
	var s1 = (txtarea.value).substring(0, selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1+openTag+s2+closeTag+s3;
}
		
function IEWrap(openTag, closeTag){
	strSelection = document.selection.createRange().text;
	if(strSelection != '')	document.selection.createRange().text = openTag + strSelection + closeTag;
}
	
function wrapSelection(txtarea, openTag, closeTag){
	if(document.all) IEWrap(openTag, closeTag);
	else if(document.getElementById) mozWrap(txtarea, openTag, closeTag);
	document.getElementById(txtarea).focus();
	return false;
}

function wrapSelectionWithLink(txtarea){
	var my_link = prompt('Enter URL:', 'http://');
	if(my_link == null) return false;
	if(my_link.length < 6){
		alert('This URL is not valid!');
		return false;
	}
	return wrapSelection(txtarea, '[url="http://'+my_link+'"]', '[/url]');
}

Use it like this.

<a href="java script:void(0);" onclick="wrapSelection('content', '[b]', '[/b]');">Bold</a><br />
<textarea id="content" name="content">Content Here</textarea>

Just use the wrapSelection() function for normal BBCode, and wrapSelectionWithLink() for using URLs.
Simple, and works just fine.

#7 _*Creative Insanity_*

  • Guests

Posted 20 April 2007 - 08:44 PM

Ahh cool have a play soon. In woodwork mode at the moment LOL

#8 _*Creative Insanity_*

  • Guests

Posted 02 May 2007 - 11:32 PM

Ok getting there but taken some time.. (slow ya see.. hehe)


I have changed my function a little and now this part works a treat.
function navcol(input,input2) {
var obj=document.getElementById(input)
obj.value+="#nav: background-color:"+input2+";"
}
But the part I cannot suss out is what to enter here to get the value of the text field dataout

<form id="data1" name="data1" method="post" action="java script:navcol('thebody','dataout'),toggleDiv('datain')">
		<input type="text" name="dataout" id="dataout" />
		<input type="submit" name="Go" id="Go" value="Go" />
		</form>
This is the last part I need to suss out and for the life me I have turned completely dumb.

anyone??

ta muchly

#9 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 03 May 2007 - 04:41 PM

I really don't get the logic of your code here...

You are making a whole form to simply add text to the field that is in the form...?

Either way you would be using your own function incorrectly here.

action="java script:navcol('thebody','dataout'),toggleDiv('datain')"

Should be more like.

action="navcol('thebody', document.getElementById('dataout').value);toggleDiv('datain')"

You need to end a line of code with semicolons, especially when they are all put into one line (like bookmarklets). Also, you don't need 'java script:' in your action attribute there.

#10 _*Creative Insanity_*

  • Guests

Posted 04 May 2007 - 05:49 PM

hehe you are not the first to say that about my coding.. but atleast you said it in a kinder way than many <_< Sledge hammer coding comes to mind LOL.

But anyway your line worked a treat. But I did need to have the java script: there as without it once the button was pressed the form went off trying to find a page of the action name. But yeah all works now as I wanted.

You have helped this old fart on an number of occasions, so if there is anything I can do for you just ask.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users