Question

I managed to embed my external html-page in a mturk-hit using the iframe (external question).

If a worker accepts my HIT, the generated URL is:

https://workersandbox.mturk.com/mturk/return?groupId=260LVCNHMVHY0UMXMCB2A4K8CRQ20A&requesterId=A165LMPFHNTKFG&hitId=3180JW2OT5IAV9ZKJ6GHA2GH8KXJ51&signature=hAyO0wvGxW%2BX3Kewgv%2F2%2FhyloSI%3D&externalHit=true&canAccept=

How can I get the assignmentId out of the URL in order to use it in my form for submitting?

Here's my form:

<form name='mturk_form' method='post' id='mturk_form' action='https://workersandbox.mturk.com/mturk/externalSubmit'> <!- For real submit use : https://www.mturk.com/mturk/externalSubmit-->
<input type='hidden' value='' name='assignmentId' id='here the assignmentId from the url should be inserted'/>
<h1>What's up?</h1>
<p><textarea name='comment' cols='80' rows='3'></textarea></p>
<p><input type='submit' id='submitButton' value='Submit' /></p>
</form>
Was it helpful?

Solution

You need to add some javascript to the ExternalHIT HTML that will extract parameters from its own URL:

function turkGetParam( name ) { 
    var regexS = "[\?&]"+name+"=([^&#]*)"; 
    var regex = new RegExp( regexS ); 
    var tmpURL = fullurl; 
    var results = regex.exec( tmpURL ); 
    if( results == null ) { 
        return ""; 
    } else { 
        return results[1];    
    } 
}

// ASSIGNS THE URL PARAMETERS TO JAVASCRIPT VARIABLES
var assign = turkGetParam('assignmentId');
var hit = turkGetParam('hitId');
var worker = turkGetParam('workerId');

You can then use the assign variable to do whatever you want (e.g., printing to the page writing to a form field, etc.).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top