document.getElementById not working

wakespirit
Kilo Guru

Dear all,

I have a record producer that I am displaying in a GlideModal using below script :

var gform=new GlideModal('test_producer',false,'modal-lg');

Then I have a UI page named "test producer" define as below :

HTML script :

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
		<button id="close" onclick="closeAck()" type="button">$[gs.getMessage("Close")]</button>
	<div>
	
	<iframe id="rp_frame" src="/com.glideapp.servicecatalog_cat_item_view.do?v=1${AMP}sysparm_id=a57bed012f8ba30061999bacf699b64e" width="800" height="600">
		</iframe>
		
	</div>
<script>

addLoadEvent( function() {
onLoadFunction();

});


</script>	
</j:jelly>

Client Script :

function closeAck() {
	alert("CLOSE ACK REACH");
	GlideDialogWindow.get().destroy();
	//saveProducer();
}

function onLoadFunction()
{
   alert("FRAME LOADED");
	var iframe = document.getElementById('rp_frame');
	 if(iframe){
       
	 var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
	  var button = innerDoc.getElementById("submit_button");
		 if(button){
		   var mybuttonValue= button.value;
			 	alert("SUBMIT BUtton : " + mybuttonValue)  ;
		 }
		 else{
			 alert("SUBMIT BUTTON NOT FOUND")  ;
		}
    }
	else{
			 alert("IFRAME NOT FOUND")  ;
	}
	
}

What I am trying to do is to get the Submit_button of the record procuder which is embeded in the Iframe.

For some reason I cannot reach the buttton id using getElement, the alert message "SUBMIT BUTTON" is displayed

What i am doing wrong ? does it means the button is not yet ready when onload method is called ? how should I change my script to be able to reach the submit button 
?

Below is the debug view element of my button I need to catch :

<button type="button" id="submit_button" name="submit_button" class="request_catalog_button header_button btn cat-btn btn-primary" href="#" onclick="saveProducer('');" title="" aria-label="Submit" data-html="true" role="button" data-original-title="Submit">
			Submit
			<span class="sr-only">Submit</span></button>

 

once I am able to access this button, I need to register to the onclick event in order to run a script, but as you can see from below the click event of the button is already calling saveProcuder(''), can I register to this event and run an other script in parallel ?

Thnaks to help me to know why i cannot fetch my button and register to its click event

regarsd

13 REPLIES 13

Not quite sure about this one

Hello Ali,

I find a way to catch the Submit button event of my record producer.
On record producer you are able to define different client script and specify when you want them to execute (Onload, onChange, onSubmit)

I define a client script in which I simply add a Alert message to see if it is catch as below :

find_real_file.png

Now the question is how can I close my GlideDialog from that script, any idea ?

I have try to use GlideWindow.get().destroy() but it does not work

Hi 

Try to solve the issue by using AJAX in an onSubmit client script to have the form submit, then close.

how ? could you please send me sample I am not so familar with this.

can you show how to close with what you say ajax?

Hi 

By that i mean do it via Script include at the backend. 

GlideWindow.get().destroy() will work in Script include.